#include <iostream>
#include <vector>

using namespace std;

// 8a

template< typename FIRST, typename SECOND >
class Pair
{
public:
   FIRST first;
   SECOND second;

   Pair(FIRST first, SECOND second)
   {
      this->first = first;
      this->second = second;
   }
   
   friend ostream& operator <<(ostream& os, const Pair& pair)
   {
      cout << "(" << pair.first.c_str() << " : " << pair.second << ")"; 
      return os;
   }
};

// 8b

template< typename KEY, typename DATA >
class VectorMap
{
   vector< Pair<KEY, DATA> > vec;
   
public:
   friend ostream& operator <<(ostream& os, const VectorMap& map)
   {
      cout << "{";
      for (int i = 0; i < map.vec.size(); i++)
      {
         cout << map.vec[i]; 
         if (i < map.vec.size() - 1)
            cout << " ";
      }
      cout << "}";
      return os;
   }

   void clear()
   {
      vec.clear();
   }
   
   int size()
   {
      return vec.size();
   }
   
   DATA& operator [](KEY key)
   {
      for (int i = 0; i < vec.size(); i++)
      {
         if (vec[i].first.compare(key) == 0)
         {
            return vec[i].second;
         }
      }
      
      Pair<KEY, DATA> p(key, DATA());
      vec.push_back(p);
      return vec.back().second;
   }
};

// 8c

int main()
{
   VectorMap<string, int> map;

   map["dog"] = 1;
   map["cat"] = 12;
   map["dog"]++;
 
   cout << map << endl;
   
   return 0;
}
